<template>
  <div class="page-container">
    <SearchPanel @change="handleSearchPanelChange">
      <el-form
        ref="queryForm"
        class="query-more-form"
        size="mini"
        label-width="100px"
        :model="query"
      >
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="编号" prop="number">
              <el-input
                v-model="query.number"
                placeholder="请输入编号"
                clearable
                size="small"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="标题" prop="title">
              <el-input
                v-model="query.title"
                placeholder="请输入标题"
                clearable
                size="small"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="关键字" prop="keyword">
              <el-input
                v-model="query.keyword"
                placeholder="请输入关键字"
                clearable
                size="small"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6" class="btn-col">
            <el-button size="mini" class="search-btn" @click="initData"
              >查询</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </SearchPanel>
    <div class="table-container">
      <div class="table-tools-panel table-flex-row">
        <div class="table-btns-left">
          <el-button
            class="flush-btn yellow"
            icon="el-icon-plus"
            @click="addCust"
            >新增</el-button
          >
          <el-button
            class="flush-btn"
            size="mini"
            icon="el-icon-refresh"
            @click="Refresh"
            >刷新</el-button
          >
        </div>
        <div>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-printer"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-share"
          ></el-button>
        </div>
      </div>
      <div class="table-list-panel">
        <el-table
          v-loading="tableLoading"
          border
          size="small"
          :data="tableData"
          :height="isShow ? 'calc(100vh - 465px)' : 'calc(100vh - 335px)'"
          style="width: 100%"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column
            prop="number"
            label="编号"
            align="center"
            width="100"
            show-overflow-tooltip
          />
          <el-table-column
            prop="title"
            label="标题"
            align="center"
            width="150"
            show-overflow-tooltip
          />
          <el-table-column
            label="关键词"
            align="center"
            prop="keyword"
            show-overflow-tooltip
          />
          <el-table-column
            label="大类名称"
            align="center"
            prop="subClassCompleteName"
            show-overflow-tooltip
          />
          <el-table-column
            label="小类名称"
            align="center"
            prop="subClassName"
            show-overflow-tooltip
          />
          <el-table-column
            label="创建时间"
            align="center"
            prop="categoryDcaName"
            width="150"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <div>
                {{ parseTime(scope.row.createTime) }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="来源部门"
            align="center"
            prop="deptValue"
            width="150"
            show-overflow-tooltip
          />

          <el-table-column
            label="内容"
            align="center"
            prop="content"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <el-tooltip placement="top">
                <div slot="content">点击复制</div>
                <span
                  style="display: block; cursor: pointer"
                  class="tag-read"
                  :data-clipboard-text="scope.row.content"
                  @click="copy"
                  >{{ scope.row.content }}</span
                >
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" fixed="right">
            <template slot-scope="scope">
              <el-button
                class="table-inner-btn"
                type="text"
                size="mini"
                @click="handleDetails(scope.row)"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-panel">
        <Pagination
          :total="query.total"
          :page.sync="query.pageNum"
          :limit.sync="query.pageSize"
          @pagination="initData"
        />
      </div>
    </div>
    <KnowledgeDetailsDialog
      :dialogVisible="dialogVisible"
      @closeDialog="dialogVisible = false"
      :obj="obj"
    />
    <KnowledgeDetailsDialogAdd
      :dialogVisible="visibleAdd"
      @closeDialog="visibleAdd = false"
      :obj="obj"
      @getNewPage="getNewPage"
    />
  </div>
</template>

<script>
import { listKnowledge } from "@/api/system/knowledge";
import { knowledgeMsg } from "@/api/knowledgeBase.js";
import SearchPanel from "@/components/SearchPanel";
import { parseTime } from "@/utils/index";
import Pagination from "@/components/Pagination";
import KnowledgeDetailsDialog from "./components/knowledgeDetailsDialog";
import KnowledgeDetailsDialogAdd from "./components/knowledgeDetailsDialogAdd";
export default {
  name: "Knowledge",
  components: {
    SearchPanel,
    Pagination,
    KnowledgeDetailsDialog,
    KnowledgeDetailsDialogAdd,
  },
  data() {
    return {
      isShow: true,
      query: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        keyword: "",
        title: "",
        number: "",
      },
      tableLoading: false,
      tableData: [],
      dialogVisible: false,
      visibleAdd: false,
      obj: {},
    };
  },
  created() {
    this.initData();
  },
  mounted() {},
  methods: {
    parseTime,
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    initData() {
      this.tableLoading = true;
      const query = JSON.parse(JSON.stringify(this.query));
      knowledgeMsg(query)
        .then((res) => {
          this.tableLoading = false;
          this.query.total = res.total;
          this.tableData = res.rows;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    // 查看详情
    handleDetails(row) {
      this.obj = JSON.parse(JSON.stringify(row));
      this.dialogVisible = true;
      console.log(row);
    },
    // 新增
    addCust() {
      this.visibleAdd = true;
      this.dialogType = "add";
      this.obj = {};
    },

    copy() {
      var clipboard = new this.Clipboard(".tag-read");
      clipboard.on((e) => {
        this.$message.success("复制成功");
        // 释放内存
        clipboard.destroy();
      });
      clipboard.on("error", (e) => {
        // 不支持复制
        console.log("该浏览器不支持自动复制");
        // 释放内存
        clipboard.destroy();
      });
    },


    // 新增成功后，刷新页面
    getNewPage() {
      this.initData();
    },

    // 刷新功能
    Refresh() {
      this.initData();
    },
  },
};
</script>

<style lang='scss' scoped>
</style>
